#include <iostream>
#include <algorithm>
#include <set>
#include <string>

using namespace std;

typedef struct
{
    string name;
    int fs[3];
    int total;
} Data;

bool compare(const Data& a, const Data& b)
{
    return a.total >= b.total;
}

int main(int argc, char const *argv[])
{
    multiset<string>::iterator p;
    multiset<string> results;
    Data datas[1024], temp;
    int n, i, j, k;
    cin >> n;
    for (i = 0; i < n; i++)
    {
        cin >> temp.name
            >> temp.fs[0]
            >> temp.fs[1]
            >> temp.fs[2];
        temp.total = temp.fs[0] + temp.fs[1] + temp.fs[2];
        datas[i] = temp;
    }

    sort(datas, datas + n, compare);

    for (i = 0; i < n; i++)
    {
        for (j = i + 1; j < n; j++)
        {
            if (datas[i].total - 10 > datas[j].total)
            {
                break;
            }
            
            for (k = 0; k < 3; k++)
            {
                if (abs(datas[i].fs[k] - datas[j].fs[k]) > 5)
                {
                    break;
                }
            }

            if (k == 3)
            {
                if (datas[i].name <= datas[j].name)
                {
                    results.insert(datas[i].name + " " + datas[j].name);
                }
                else
                {
                    results.insert(datas[j].name + " " + datas[i].name);
                }
            }
        }
    }

    for (p = results.begin(); p != results.end(); p++)
    {
        if (p != results.begin()) cout << "\n";
        cout << *p;
    }
    
    return 0;
}
